/* SPU Parallel Elliptic Curve Library - Provides Elliptic Curve Cryptographic
 * functions to the Synergistic Processing Unit target platform
 *
 * Copyright (C) 2008  Michael Annichiarico (mike.gcdeveloper@gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef SPEC_H
#define SPEC_H

#include"../../field2m/include/field2m.h"

typedef struct ECPOINTu_st {
	FIELD2M x;
	FIELD2M y;
	FIELD2M z;
} __attribute__((aligned (16))) ECPOINT, *PECPOINT;
/*
typedef union ECPOINT_st {
		ECPOINTu p;
		FIELD2M a[3];
} __attribute__((aligned (16))) ECPOINT, *PECPOINT;
*/
typedef struct ECGROUP_st {
	ECPOINT G;
	FIELD2M n; /* the order of the group.(nG==1)  Stored in a FIELD2M, but actually a big integer. */
	FIELD2M nbe; /* the order of the group.(nG==1)  Stored in a FIELD2M, but actually a big integer (in big endian so it works with libmpm. */
	FIELD2M c; /* c^2 = b */
	FIELD2M a; 
	FIELD2M b; 
} __attribute__((aligned (16))) ECGROUP, *PECGROUP;

extern ECPOINT spec_point_LDinf;
extern ECPOINT spec_point_Ainf;

void spec_point_print(PECPOINT p);
int spec_point_cmpeq(PECPOINT P, PECPOINT Q);
void spec_point_LD2A(PECGROUP GRP, PECPOINT Q, PECPOINT P);
void spec_point_LDdbl(PECGROUP GRP, PECPOINT P3, PECPOINT P1);
void spec_point_LDadd(PECGROUP GRP, PECPOINT P3, PECPOINT P1, PECPOINT P2);
void spec_point_LDkP(PECGROUP GRP, PECPOINT Q, PFIELD2M k, PECPOINT P);
void spec_point_Mxy(PECGROUP GRP, PECPOINT P, PECPOINT P1, PECPOINT P2);
void spec_point_Mdbl(PECGROUP GRP, PECPOINT P);
void spec_point_Madd(PECGROUP GRP, PFIELD2M x, PECPOINT P1, PECPOINT P2);
void spec_point_MkP(PECGROUP GRP, PECPOINT Q, PFIELD2M k, PECPOINT P);
void spec_point_MkP_be(PECGROUP GRP, PECPOINT Q, PFIELD2M k, PECPOINT P);
int spec_ecdsa_sign(PECGROUP GRP, PFIELD2M kbe, PFIELD2M d, PFIELD2M e, PFIELD2M r, PFIELD2M s);
int spec_ecdsa_verify(PECGROUP GRP, PECPOINT Q, PFIELD2M e, PFIELD2M r, PFIELD2M s);
void spec_point_simulMkP_be(PECGROUP GRP, PECPOINT R, PFIELD2M k, PECPOINT P, PFIELD2M l, PECPOINT Q);

extern ECGROUP nistb233grp;

//#define DBG(xxx) xxx
#define DBG(xxx)

#endif
